//引入样式
require('../css/commonCss/normalize.css')
require('../css/commonCss/reset.css')
require('../css/commonCss/property.css')
require('../css/commonCss/basic.less')
require('../fonts/iconfont.css')

require('../css/mine.less')
//引入axios
const axios = require('axios')
//weui—插件库
require('weui')
const weui = require('weui.js')
// 导入util js
const util = require('../util/util.js')

// 文档加载事件
document.addEventListener('DOMContentLoaded', function () {
    /* 
        0:获取元素
    */
    // 用户名
    const nickname = document.querySelector('#nickname')
    // 个性签名
    const sign = document.querySelector('#sign')
    const imgurl = document.querySelector('#imgurl')
    const quit = document.querySelector('#quit')
    const dynamicCount = document.querySelector('#dynamicCount')
    const times = document.querySelector('#times')
    const calorie = document.querySelector('#calorie')
    const mineUser = document.querySelector('#mineUser')
    const movementData = document.querySelector('#movementData')//运动数据
    const medal = document.querySelector('#medal')//我的运动勋章

    // 返回上一个页面
    mineUser.addEventListener('click',function(){
        location.href='./personaldata.html'
    })

    axios.get('http://139.9.177.51:8099/users/mysportsBadge', {
    params: {
        userId: localStorage.getItem('userId')
    }
    }).then(function (res) {
        // console.log(res);
        let user = res.data.data.user;
        // console.log(user);
        // 渲染数据
        if(user.imgurl){
            imgurl.src = user.imgurl;
        }
        if(user.nickname){
            nickname.textContent = user.nickname;
        }
        if(user.sign){
            sign.textContent = user.sign;
        }
        dynamicCount.textContent = res.data.data.dynamicCount;

        times.textContent = res.data.data.sports.times;

        calorie.textContent = res.data.data.sports.calorie;

    })
    // 退出登录
    quit.addEventListener('click', function () {
        weui.confirm("确定要退出吗?",function(){
            console.log("您点击了确定按钮");
            // 清除本次存储
            localStorage.clear()
            //跳转到登录页面
            location.href = './login.html'
        })
    })

    // 点击运动数据跳转页面
    movementData.addEventListener('click',function(){
        location.href = './mySportData.html'
    })
    // 点击我的运动勋章跳转页面
    medal.addEventListener('click',function(){
        location.href = './myBadges.html'
    })
    /* 
        1:底部导航
    */
  util.fixBottomNav('mine');
})

